import Vue from 'vue'
import App from './App.vue'
//导入路由模块
import router from './router'

import axios from 'axios'

//完整引入element-ui
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import { Loading } from 'element-ui'


Vue.config.productionTip = false

Vue.use(ElementUI)

Vue.filter('dateFormat', (dtstr) => {
  const dt = new Date(dtstr)

  const y = padZero(dt.getFullYear())
  const m = padZero(dt.getMonth() + 1)
  const d = padZero(dt.getDate())


  const hh = padZero(dt.getHours())
  const mm = padZero(dt.getMinutes())
  const ss = padZero(dt.getSeconds())

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`

})

function padZero(n) {
  return n > 9 ? n : '0' + n
}
//在全局配置axios

// axios.defaults.baseURL = 'https://www.escook.cn'


axios.defaults.baseURL = 'http://localhost:3000/'

Vue.prototype.$http = axios
//声明请求拦截器
let LoadingInstance = null
axios.interceptors.request.use((config) => {
  //展示Loading效果
  LoadingInstance = Loading.service({ fullscreen: true })
  return config
})
//声明响应拦截器
axios.interceptors.response.use((response) => {
  //隐藏Loading效果
  LoadingInstance.close()
  return response
})

new Vue({
  //挂载路由
  router,
  render: h => h(App),
}).$mount('#app')

